/*
 * Copyright @2007-2008 by Infowarelab Webapps.
 */
package kevin.study.zephyr.util;

import kevin.study.zephyr.domain.dao.IDAOFactory;
import kevin.study.zephyr.domain.factory.DocumentFactory;
import kevin.study.zephyr.domain.model.Entity;
import kevin.study.zephyr.platform.Platform;

import java.util.List;
import java.util.Observer;

/**
 * HISTORY
 * <p/>
 * 暴露给Spring的接口
 *
 * @author Kevin.Huang
 * @createtime 2008-3-17 下午03:17:14
 */
public final class SpringContext {

    /**
     * 载入Entity 类型
     *
     * @param value
     */
    @SuppressWarnings("unchecked")
    public void setEntity(List<String> value) {
        for (String v : value) {
            String en = v.replaceAll("\n", "").replaceAll("\r", "").trim();
            try {
                Platform.getItemManager().registerItemEntity(
                        (Class<? extends Entity>) Class.forName(en));
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Error Parameter!");
            }
        }
    }

    /**
     * 载入DaoFactory
     *
     * @param daoFactory
     */
    public void setDaoFactory(IDAOFactory daoFactory) {
        Platform.getDBManager().setDaoFactory(daoFactory);
    }

    /**
     * 载入观察者
     *
     * @param observers
     */
    public void setDBManagerObserver(List<Observer> observers) {
        for (Observer o : observers) {
            Platform.getDBManager().addObserver(o);
        }
    }

    /**
     * 载入DocumentFactory
     *
     * @param documentFactory
     */
    public void setDocumentFactory(DocumentFactory documentFactory) {
        Platform.getDocumentManager().setDocumentFactory(documentFactory);
    }

}
